package com.carkeeper.shop.check.controller;

import com.carkeeper.entity.PageResult;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.shop.check.service.CheckStoreService;
import com.carkeeper.shop.pojo.Store;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RequestMapping("/check")
@Api(tags = "主体审核")
@RestController
public class CheckStoreOrder {

    @Autowired
    private CheckStoreService checkStoreService;

    /**
     * 分页展示审核中的服务商
     *
     * @param searchMap
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findPage/{page}/{size}")
    @ApiOperation("查询列表接口")//标注方法
    public PageResult findPage(@RequestParam Map searchMap, @PathVariable("page") String page, @PathVariable("size") String size) {
        Page<Store> storePage = checkStoreService.findPage(searchMap, page, size);
        PageResult pageResult = new PageResult<Store>(storePage.getTotal(), storePage.getResult());
        return pageResult;
    }

    /**
     * 已拒绝服务商主体
     *
     * @param searchMap
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/turn/{page}/{size}")
    @ApiOperation("已拒绝主体展示")
    public PageResult turn(@RequestParam Map searchMap, @PathVariable("page") String page, @PathVariable("size") String size) {
        Page<Store> storePage = checkStoreService.turn(searchMap, page, size);
        return new PageResult<Store>(storePage.getTotal(), storePage.getResult());
    }

    /**
     * 展示待商家审核信息
     *
     * @param id
     * @return
     */
    @GetMapping("/show/{id}")
    @ApiOperation("商家详情信息")
    public Result<Store> show(@PathVariable("id") String id) {
        Store store = checkStoreService.show(id);
        return new Result<Store>(true, StatusCode.OK, "", store);
    }

    /**
     * 审核
     */
    @PutMapping("/store/{id}/{status}")
    @ApiOperation("服务商审核")
    public Result check(@PathVariable("id") String id, @PathVariable("status") String status) {
        return checkStoreService.check(id, status);
    }
}
